package wch;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import robocode.control.testing.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;


/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that DaRumble can beat
 * Crazy.
 * 
 * @author Christopher Wilson
 */
public class TestDaRumbleVersusCrazy extends RobotTestBed {
  private boolean wonBattles = false;

  /**
   * Specifies that Crazy and DaRumble are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,wch.DaRumble";
  }

  /**
   * This test runs for 20 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 20;
  }

  /**
   * The actual test, which asserts that Darumble has won a small percentage of rounds against
   * Crazy.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] Results = event.getIndexedResults();
    // Sanity check that results[1] is DaRumble (not strictly necessary, but illustrative).
    BattleResults daRumbleResults = Results[1];
    String botName = daRumbleResults.getTeamLeaderName();
    assertEquals("Check that results[1] is DaRumble", botName, "wch.DaRumble*");
    if (daRumbleResults.getFirsts() >= 1) {
      wonBattles = true;
    }
    // Check to make sure DaRumble won at least once.
    assertTrue("Check DaRumble can be victorious", wonBattles);
  }

}
